<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>Introduction_to_Algorithms: IntroductionToAlgorithm::SortAlgorithm::Sort_Heap&lt; Iterator, CompareType &gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Introduction_to_Algorithms
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pri-attribs">Private Attributes</a> &#124;
<a href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap&lt; Iterator, CompareType &gt; Class Template Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Sort_Heap：用于堆排序的堆，算法导论第6章  
 <a href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="heapsort_8h_source.html">heapsort.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:a5af910656f5d3c65d47f992dbf380c61"><td class="memItemLeft" align="right" valign="top">typedef std::iterator_traits&lt; Iterator &gt;::value_type&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a5af910656f5d3c65d47f992dbf380c61">T</a></td></tr>
<tr class="separator:a5af910656f5d3c65d47f992dbf380c61"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:adfaf638a6fd27c6295f7ac0a07484a00"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#adfaf638a6fd27c6295f7ac0a07484a00">operator()</a> (const Iterator from, std::size_t size, CompareType compare=CompareType())</td></tr>
<tr class="memdesc:adfaf638a6fd27c6295f7ac0a07484a00"><td class="mdescLeft">&#160;</td><td class="mdescRight">operator()  <a href="#adfaf638a6fd27c6295f7ac0a07484a00">More...</a><br /></td></tr>
<tr class="separator:adfaf638a6fd27c6295f7ac0a07484a00"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a64c05fac6da6e6e0d63e733640d0cf97"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a64c05fac6da6e6e0d63e733640d0cf97">_setupHeap</a> (CompareType compare=CompareType())</td></tr>
<tr class="memdesc:a64c05fac6da6e6e0d63e733640d0cf97"><td class="mdescLeft">&#160;</td><td class="mdescRight">_setupHeap:建堆  <a href="#a64c05fac6da6e6e0d63e733640d0cf97">More...</a><br /></td></tr>
<tr class="separator:a64c05fac6da6e6e0d63e733640d0cf97"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0535910130c6c750faf7801059e4a9fa"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a0535910130c6c750faf7801059e4a9fa">_heapify</a> (std::size_t elementIndex, CompareType compare=CompareType())</td></tr>
<tr class="memdesc:a0535910130c6c750faf7801059e4a9fa"><td class="mdescLeft">&#160;</td><td class="mdescRight">_heapify：维持堆性质  <a href="#a0535910130c6c750faf7801059e4a9fa">More...</a><br /></td></tr>
<tr class="separator:a0535910130c6c750faf7801059e4a9fa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a72f5fa2e41901a80fdb9a3bcece8a33f"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a72f5fa2e41901a80fdb9a3bcece8a33f">_parentIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:a72f5fa2e41901a80fdb9a3bcece8a33f"><td class="mdescLeft">&#160;</td><td class="mdescRight">_parentIndex:返回一个节点的父节点位置  <a href="#a72f5fa2e41901a80fdb9a3bcece8a33f">More...</a><br /></td></tr>
<tr class="separator:a72f5fa2e41901a80fdb9a3bcece8a33f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af4033a3e0cd7dab78cb1081f3dece165"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#af4033a3e0cd7dab78cb1081f3dece165">_lchildIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:af4033a3e0cd7dab78cb1081f3dece165"><td class="mdescLeft">&#160;</td><td class="mdescRight">_lchildIndex:返回一个节点的左子节点位置  <a href="#af4033a3e0cd7dab78cb1081f3dece165">More...</a><br /></td></tr>
<tr class="separator:af4033a3e0cd7dab78cb1081f3dece165"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a71532dbfd31fdb854aa46dbca6e411ac"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a71532dbfd31fdb854aa46dbca6e411ac">_rchildIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:a71532dbfd31fdb854aa46dbca6e411ac"><td class="mdescLeft">&#160;</td><td class="mdescRight">_rchildIndex:返回一个节点的右子节点位置  <a href="#a71532dbfd31fdb854aa46dbca6e411ac">More...</a><br /></td></tr>
<tr class="separator:a71532dbfd31fdb854aa46dbca6e411ac"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-attribs"></a>
Private Attributes</h2></td></tr>
<tr class="memitem:a484d28581bfe39a387d90852e38ac36c"><td class="memItemLeft" align="right" valign="top">Iterator&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a484d28581bfe39a387d90852e38ac36c">_from</a></td></tr>
<tr class="separator:a484d28581bfe39a387d90852e38ac36c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a57a42830d3b52d60d2ec1dfd11e2bda6"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a57a42830d3b52d60d2ec1dfd11e2bda6">_size</a></td></tr>
<tr class="separator:a57a42830d3b52d60d2ec1dfd11e2bda6"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt;<br />
class IntroductionToAlgorithm::SortAlgorithm::Sort_Heap&lt; Iterator, CompareType &gt;</h3>

<p>Sort_Heap：用于堆排序的堆，算法导论第6章 </p>
<ul>
<li>堆排序思想：假设对数组A[p...r]排序：首先将数组构建成一个最大堆（或者最小堆，这里的实现采用最大堆）。然后第一个元素就是堆中最大的元素。 将第一个元素与最后一个元素交换，同时堆的规模缩减1，再将堆维持最大堆性质。不断循环最后得到一个排序好的序列</li>
<li>时间复杂度 O(nlogn)</li>
<li>原地排序</li>
</ul>
<p>堆排序有两个重要操作：</p>
<ul>
<li>heapify(index)操作：维持以index为根节点的子堆的性质。它比较index与其左右子节点的值，选取其最大的那个提升到index节点上。同时递归向下。具体见_heapify()方法说明</li>
<li>setupHeap()操作： 建堆操作。它从堆的最低层向上层反复调用heapify操作进行建堆。 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00040">40</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>
</div><h2 class="groupheader">Member Typedef Documentation</h2>
<a class="anchor" id="a5af910656f5d3c65d47f992dbf380c61"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">typedef std::iterator_traits&lt;Iterator&gt;::value_type <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::<a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a5af910656f5d3c65d47f992dbf380c61">T</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>迭代器指向对象的值类型 </p>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00043">43</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a0535910130c6c750faf7801059e4a9fa"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_heapify </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">CompareType&#160;</td>
          <td class="paramname"><em>compare</em> = <code>CompareType()</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_heapify：维持堆性质 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 要维持以该节点为根节点的子堆的堆性质 </td></tr>
    <tr><td class="paramname">compare</td><td>一个可调用对象，可用于比较两个对象的小于比较，默认为std::less&lt;T&gt; </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void</dd></dl>
<p>首先调用比较该节点与左右子节点的最大值。如果最大值为它本身，则维持了性质，返回；如果最大值不是它本身，那么必然为左、右子节点之一。 将该最大节点（假设为左子节点）交换到根节点，然后以左子节点递归调用heapify操作</p>
<ul>
<li>时间复杂度 O(n)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00102">102</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="af4033a3e0cd7dab78cb1081f3dece165"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_lchildIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_lchildIndex:返回一个节点的左子节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示子节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>左子节点位置(std::size_t)</dd></dl>
<p>根据最大堆的性质，一个节点elementIndex的左子节点是它的位置(elementIndex/2)+1</p>
<ul>
<li>当最大堆大小为0、1时，它没有左子节点，左子节点无效</li>
<li>当左子节点超过堆大小时，它无效 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00162">162</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="a72f5fa2e41901a80fdb9a3bcece8a33f"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_parentIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_parentIndex:返回一个节点的父节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 子节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示父节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>父节点位置(std::size_t)</dd></dl>
<p>根据最大堆的性质，一个子节点elementIndex的父节点是它的位置(elementIndex-1)/2。</p>
<ul>
<li>超出堆大小的节点，其父节点无效 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00139">139</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="a71532dbfd31fdb854aa46dbca6e411ac"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_rchildIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_rchildIndex:返回一个节点的右子节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示子节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>右子节点位置(std::size_t)</dd></dl>
<p>根据最大堆的性质，一个节点elementIndex的右子节点是它的位置(elementIndex/2)+2</p>
<ul>
<li>当最大堆大小为0、、1、2时，它没有右子节点，右子节点无效</li>
<li>当右子节点超过堆大小时，它无效 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00190">190</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="a64c05fac6da6e6e0d63e733640d0cf97"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_setupHeap </td>
          <td>(</td>
          <td class="paramtype">CompareType&#160;</td>
          <td class="paramname"><em>compare</em> = <code>CompareType()</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_setupHeap:建堆 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">compare</td><td>一个可调用对象，可用于比较两个对象的小于比较，默认为std::less&lt;T&gt; </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void</dd></dl>
<p>从后一半的元素开始依次向前调用heapify操作（根据最大堆性质，除了最底层它是完全充满的）</p>
<ul>
<li>时间复杂度 O(nlogn)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00079">79</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="adfaf638a6fd27c6295f7ac0a07484a00"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::operator() </td>
          <td>(</td>
          <td class="paramtype">const Iterator&#160;</td>
          <td class="paramname"><em>from</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">CompareType&#160;</td>
          <td class="paramname"><em>compare</em> = <code>CompareType()</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>operator() </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">from</td><td>: 待排序序列的起始迭代器（也可以是指向数组中某元素的指针） </td></tr>
    <tr><td class="paramname">size</td><td>待排序序列的长度 </td></tr>
    <tr><td class="paramname">compare</td><td>一个可调用对象，可用于比较两个对象的小于比较，默认为std::less&lt;T&gt; </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void</dd></dl>
<p>首先调用 <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html#a64c05fac6da6e6e0d63e733640d0cf97" title="_setupHeap:建堆 ">_setupHeap()</a>建堆。然后再反复抽取最大值到堆尾部，然后维持堆的性质。</p>
<ul>
<li>时间复杂度 O(nlogn)</li>
<li>原地排序 </li>
</ul>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00056">56</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Data Documentation</h2>
<a class="anchor" id="a484d28581bfe39a387d90852e38ac36c"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">Iterator <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_from</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>堆根节点位置 </p>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00206">206</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<a class="anchor" id="a57a42830d3b52d60d2ec1dfd11e2bda6"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Iterator, typename CompareType = std::less&lt;typename std::iterator_traits&lt;Iterator&gt;::value_type&gt;&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">IntroductionToAlgorithm::SortAlgorithm::Sort_Heap</a>&lt; Iterator, CompareType &gt;::_size</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>堆大小 </p>

<p>Definition at line <a class="el" href="heapsort_8h_source.html#l00207">207</a> of file <a class="el" href="heapsort_8h_source.html">heapsort.h</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>src/sort_algorithms/heap_sort/<a class="el" href="heapsort_8h_source.html">heapsort.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="namespace_introduction_to_algorithm.html">IntroductionToAlgorithm</a></li><li class="navelem"><a class="el" href="namespace_introduction_to_algorithm_1_1_sort_algorithm.html">SortAlgorithm</a></li><li class="navelem"><a class="el" href="class_introduction_to_algorithm_1_1_sort_algorithm_1_1_sort___heap.html">Sort_Heap</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
